@lyfie/luthor-headless 2.6.5 → 2.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,6 +37,10 @@ Optional:
37
37
  pnpm add highlight.js @emoji-mart/data
38
38
  ```
39
39
 
40
+ Code-block grammars for common languages
41
+ (`bash`, `json`, `yaml`, `go`, `php`, `ruby`, `csharp`, `kotlin`, `jsx`, `tsx`, `graphql`, `docker`, `toml`, `lua`, `perl`, `r`, `scala`, `dart`) are supported with optional Prism loading.
42
+ By default, `CodeExtension` uses lazy grammar loading and only fetches grammars when code blocks actually use them.
43
+
40
44
  ## Quick Usage
41
45
 
42
46
  ```tsx
package/dist/index.d.ts CHANGED
@@ -427,16 +427,16 @@ declare function isLuthorTheme(theme: any): theme is LuthorTheme;
427
427
  declare function clearLexicalSelection(editor: LexicalEditor): void;
428
428
  declare function resolveLinkNodeKeyFromAnchor(editor: LexicalEditor, anchorEl: HTMLAnchorElement): string | null;
429
429
 
430
- type JsonRecord = Record<string, unknown>;
430
+ type JsonRecord$1 = Record<string, unknown>;
431
431
  type JsonDocument = {
432
- root: JsonRecord;
432
+ root: JsonRecord$1;
433
433
  };
434
434
  type BridgeMode = "markdown" | "html";
435
435
  type MetadataEnvelope = {
436
436
  id: string;
437
437
  type: string;
438
438
  path: number[];
439
- node: JsonRecord;
439
+ node: JsonRecord$1;
440
440
  fallback: string;
441
441
  strategy?: "replace" | "merge";
442
442
  };
@@ -457,11 +457,35 @@ declare function appendMetadataEnvelopes(content: string, envelopes: readonly Me
457
457
  declare function extractMetadataEnvelopes(content: string): ExtractedMetadataEnvelopes;
458
458
  declare function rehydrateDocumentFromEnvelopes(document: JsonDocument, envelopes: readonly MetadataEnvelope[]): JsonDocument;
459
459
 
460
- declare function markdownToJSON(markdown: string): JsonDocument;
461
- declare function jsonToMarkdown(input: unknown): string;
460
+ type SourceMetadataMode = "preserve" | "none";
461
+ type MarkdownBridgeFlavor = "github" | "luthor" | "lexical-native";
462
+ interface MarkdownBridgeOptions {
463
+ metadataMode?: SourceMetadataMode;
464
+ bridgeFlavor?: MarkdownBridgeFlavor;
465
+ }
466
+ declare function markdownToJSON(markdown: string, options?: MarkdownBridgeOptions): JsonDocument;
467
+ declare function jsonToMarkdown(input: unknown, options?: MarkdownBridgeOptions): string;
462
468
 
463
- declare function htmlToJSON(html: string): JsonDocument;
464
- declare function jsonToHTML(input: unknown): string;
469
+ interface HtmlBridgeOptions {
470
+ metadataMode?: SourceMetadataMode;
471
+ }
472
+ declare function htmlToJSON(html: string, options?: HtmlBridgeOptions): JsonDocument;
473
+ declare function jsonToHTML(input: unknown, options?: HtmlBridgeOptions): string;
474
+
475
+ type JsonRecord = Record<string, unknown>;
476
+ type BridgeRepresentabilityContext = {
477
+ node?: JsonRecord;
478
+ };
479
+ declare const MARKDOWN_SUPPORTED_NODE_TYPES: Set<string>;
480
+ declare const HTML_SUPPORTED_NODE_TYPES: Set<string>;
481
+ declare const MARKDOWN_TEXT_NATIVE_FORMAT_MASK: number;
482
+ declare const MARKDOWN_NATIVE_KEY_MAP: Readonly<Record<string, ReadonlySet<string>>>;
483
+ declare const HTML_NATIVE_KEY_MAP: Readonly<Record<string, ReadonlySet<string>>>;
484
+ declare function isDefaultBridgeValue(_type: string, key: string, value: unknown): boolean;
485
+ declare function isMarkdownRepresentable(type: string, key: string, value: unknown, context?: BridgeRepresentabilityContext): boolean;
486
+ declare function isHTMLRepresentable(type: string, key: string, value: unknown): boolean;
487
+ declare function extractMarkdownMetadataPatch(node: JsonRecord, type: string): JsonRecord | null;
488
+ declare function extractHTMLMetadataPatch(node: JsonRecord, type: string): JsonRecord | null;
465
489
 
466
490
  /**
467
491
  * Commands exposed by text format extensions.
@@ -1418,9 +1442,12 @@ type CodeStateQueries = {
1418
1442
  /** Check whether the current selection is within a code block */
1419
1443
  isInCodeBlock: () => Promise<boolean>;
1420
1444
  };
1445
+ type CodeGrammarPreloadMode = "lazy" | "idle" | "eager";
1421
1446
  type CodeExtensionConfig = BaseExtensionConfig & CodeHighlightProviderConfig & {
1422
1447
  syntaxHighlighting?: "auto" | "disabled";
1423
1448
  tokenizer?: CodeTokenizer | null;
1449
+ showLineNumbers?: boolean;
1450
+ grammarPreloadMode?: CodeGrammarPreloadMode;
1424
1451
  };
1425
1452
  /**
1426
1453
  * CodeExtension - Adds code block support for the Lexical editor
@@ -1447,6 +1474,8 @@ type CodeExtensionConfig = BaseExtensionConfig & CodeHighlightProviderConfig & {
1447
1474
  declare class CodeExtension extends BaseExtension<"code", CodeExtensionConfig, CodeCommands, CodeStateQueries, ReactNode[]> {
1448
1475
  private static readonly MAX_CODE_TAB_DEPTH;
1449
1476
  private codeHighlightProviderPromise;
1477
+ private lineNumberTextCache;
1478
+ private appliedLineNumberNodeKeys;
1450
1479
  constructor();
1451
1480
  /**
1452
1481
  * Register the extension with Lexical
@@ -1502,10 +1531,19 @@ declare class CodeExtension extends BaseExtension<"code", CodeExtensionConfig, C
1502
1531
  * @returns Current format or null
1503
1532
  */
1504
1533
  private getCurrentFormatSync;
1534
+ private hasCodeNodeMutations;
1505
1535
  private hasReachedCodeTabLimit;
1536
+ private ensureCodeBlockLineNumbers;
1537
+ private clearCodeBlockLineNumberAttributes;
1538
+ private getCodeBlockLineCount;
1539
+ private getCodeBlockLineNumberText;
1506
1540
  }
1507
1541
  declare const codeExtension: CodeExtension;
1508
1542
 
1543
+ declare function getDefaultPopularPrismLanguages(): string[];
1544
+ declare function loadPrismLanguages(languages: readonly string[]): Promise<string[]>;
1545
+ declare function loadPopularPrismLanguages(): Promise<string[]>;
1546
+
1509
1547
  type CodeIntelligenceCommands = {
1510
1548
  setCodeLanguage: (language: string) => void;
1511
1549
  autoDetectCodeLanguage: () => Promise<string | null>;
@@ -1524,7 +1562,6 @@ type CodeIntelligenceConfig = CodeHighlightProviderConfig & {
1524
1562
  languageOptions?: readonly string[] | CodeLanguageOptionsConfig;
1525
1563
  };
1526
1564
  declare class CodeIntelligenceExtension extends BaseExtension<"codeIntelligence", CodeIntelligenceConfig, CodeIntelligenceCommands, Record<string, never>, ReactNode[]> {
1527
- private languageOptions;
1528
1565
  constructor();
1529
1566
  register(editor: LexicalEditor): () => void;
1530
1567
  getPlugins(): ReactNode[];
@@ -1917,6 +1954,10 @@ interface ImagePayload {
1917
1954
  alt: string;
1918
1955
  /** Optional caption */
1919
1956
  caption?: string;
1957
+ /** Optional link wrapper URL for badge-style linked images */
1958
+ linkHref?: string;
1959
+ /** Optional link title for badge-style linked images */
1960
+ linkTitle?: string;
1920
1961
  /** Alignment */
1921
1962
  alignment?: Alignment;
1922
1963
  /** CSS class name for styling */
@@ -1957,6 +1998,10 @@ interface SerializedImageNode {
1957
1998
  alt: string;
1958
1999
  /** Optional caption */
1959
2000
  caption?: string;
2001
+ /** Optional link wrapper URL for badge-style linked images */
2002
+ linkHref?: string;
2003
+ /** Optional link title for badge-style linked images */
2004
+ linkTitle?: string;
1960
2005
  /** Alignment */
1961
2006
  alignment: Alignment;
1962
2007
  /** CSS class name */
@@ -2618,4 +2663,4 @@ declare class EnterKeyBehaviorExtension extends BaseExtension<"enterKeyBehavior"
2618
2663
  }
2619
2664
  declare const enterKeyBehaviorExtension: EnterKeyBehaviorExtension;
2620
2665
 
2621
- export { type Alignment, type BaseCommands, BaseExtension, type BaseExtensionConfig, BaseProvider, BlockFormatExtension, BoldExtension, type BridgeMode, CodeExtension, type CodeExtensionConfig, CodeFormatExtension, type CodeHighlightProvider, type CodeHighlightProviderConfig, type CodeIntelligenceCommands, type CodeIntelligenceConfig, CodeIntelligenceExtension, type CodeLanguageOptionsConfig, type CodeLanguageOptionsMode, type CommandPaletteCommands, CommandPaletteExtension, type CommandPaletteItem, type CommandPaletteStateQueries, type ContextMenuCommands, type ContextMenuConfig, ContextMenuExtension, type ContextMenuItem, type ContextMenuStateQueries, DraggableBlockExtension, type DraggableCommands, type DraggableConfig, type DraggableStateQueries, type EditorConfig, type EditorContextType, type EmojiCatalogAdapter, type EmojiCatalogItem, type EmojiCommands, type EmojiConfig, EmojiExtension, type EmojiStateQueries, type EmojiSuggestionState, EnterKeyBehaviorExtension, type Extension, ExtensionCategory, type ExtractCommands, type ExtractNames, type ExtractPlugins, type ExtractStateQueries, type ExtractedMetadataEnvelopes, type FloatingCommands, type FloatingConfig, type FloatingStateQueries, FloatingToolbarExtension, type FontCssLoadStrategy, type FontFamilyConfig, FontFamilyExtension, type FontFamilyOption, type FontSizeConfig, FontSizeExtension, type FontSizeOption, HistoryExtension, HorizontalRuleExtension, IframeEmbedExtension, type ImageCommands, type ImageComponentProps, ImageExtension, type ImageExtensionConfig, type ImagePayload, type ImageStateQueries, ItalicExtension, type JsonDocument, LIGHTWEIGHT_EMOJI_CATALOG, LUTHOR_EDITOR_THEME_TOKENS, type LexicalNodeRegistration, type LineHeightConfig, LineHeightExtension, type LineHeightOption, LinkExtension, ListExtension, type LuthorEditorThemeOverrides, type LuthorEditorThemeToken, type LuthorTheme, type MetadataEnvelope, type PreparedBridgeDocument, RichText, type RichTextComponentProps, type RichTextConfig, type SerializedImageNode, type SlashCommandCommands, type SlashCommandConfig, SlashCommandExtension, type SlashCommandItem, type SlashCommandMenuState, type SlashCommandStateQueries, StrikethroughExtension, SubscriptExtension, SuperscriptExtension, TabIndentExtension, type TableConfig, TableExtension, type TextColorConfig, TextColorExtension, type TextColorOption, TextFormatExtension, type TextHighlightConfig, TextHighlightExtension, type TextHighlightOption, type ToolbarItem, UnderlineExtension, YouTubeEmbedExtension, appendMetadataEnvelopes, blockFormatExtension, boldExtension, clearLexicalSelection, codeExtension, codeFormatExtension, codeIntelligenceExtension, commandPaletteExtension, contextMenuExtension, createCustomNodeExtension, createEditorSystem, createEditorThemeStyleVars, createExtension, defaultLuthorTheme, draggableBlockExtension, emojiExtension, enterKeyBehaviorExtension, extractMetadataEnvelopes, floatingToolbarExtension, fontFamilyExtension, fontSizeExtension, historyExtension, horizontalRuleExtension, htmlToJSON, iframeEmbedExtension, imageExtension, isLuthorTheme, italicExtension, jsonToHTML, jsonToMarkdown, lineHeightExtension, linkExtension, listExtension, markdownToJSON, mergeThemes, prepareDocumentForBridge, rehydrateDocumentFromEnvelopes, resolveLinkNodeKeyFromAnchor, richTextExtension, slashCommandExtension, strikethroughExtension, subscriptExtension, superscriptExtension, tabIndentExtension, tableExtension, textColorExtension, textHighlightExtension, underlineExtension, useBaseEditor, youTubeEmbedExtension };
2666
+ export { type Alignment, type BaseCommands, BaseExtension, type BaseExtensionConfig, BaseProvider, BlockFormatExtension, BoldExtension, type BridgeMode, CodeExtension, type CodeExtensionConfig, CodeFormatExtension, type CodeGrammarPreloadMode, type CodeHighlightProvider, type CodeHighlightProviderConfig, type CodeIntelligenceCommands, type CodeIntelligenceConfig, CodeIntelligenceExtension, type CodeLanguageOptionsConfig, type CodeLanguageOptionsMode, type CommandPaletteCommands, CommandPaletteExtension, type CommandPaletteItem, type CommandPaletteStateQueries, type ContextMenuCommands, type ContextMenuConfig, ContextMenuExtension, type ContextMenuItem, type ContextMenuStateQueries, DraggableBlockExtension, type DraggableCommands, type DraggableConfig, type DraggableStateQueries, type EditorConfig, type EditorContextType, type EmojiCatalogAdapter, type EmojiCatalogItem, type EmojiCommands, type EmojiConfig, EmojiExtension, type EmojiStateQueries, type EmojiSuggestionState, EnterKeyBehaviorExtension, type Extension, ExtensionCategory, type ExtractCommands, type ExtractNames, type ExtractPlugins, type ExtractStateQueries, type ExtractedMetadataEnvelopes, type FloatingCommands, type FloatingConfig, type FloatingStateQueries, FloatingToolbarExtension, type FontCssLoadStrategy, type FontFamilyConfig, FontFamilyExtension, type FontFamilyOption, type FontSizeConfig, FontSizeExtension, type FontSizeOption, HTML_NATIVE_KEY_MAP, HTML_SUPPORTED_NODE_TYPES, HistoryExtension, HorizontalRuleExtension, type HtmlBridgeOptions, IframeEmbedExtension, type ImageCommands, type ImageComponentProps, ImageExtension, type ImageExtensionConfig, type ImagePayload, type ImageStateQueries, ItalicExtension, type JsonDocument, LIGHTWEIGHT_EMOJI_CATALOG, LUTHOR_EDITOR_THEME_TOKENS, type LexicalNodeRegistration, type LineHeightConfig, LineHeightExtension, type LineHeightOption, LinkExtension, ListExtension, type LuthorEditorThemeOverrides, type LuthorEditorThemeToken, type LuthorTheme, MARKDOWN_NATIVE_KEY_MAP, MARKDOWN_SUPPORTED_NODE_TYPES, MARKDOWN_TEXT_NATIVE_FORMAT_MASK, type MarkdownBridgeFlavor, type MarkdownBridgeOptions, type MetadataEnvelope, type PreparedBridgeDocument, RichText, type RichTextComponentProps, type RichTextConfig, type SerializedImageNode, type SlashCommandCommands, type SlashCommandConfig, SlashCommandExtension, type SlashCommandItem, type SlashCommandMenuState, type SlashCommandStateQueries, type SourceMetadataMode, StrikethroughExtension, SubscriptExtension, SuperscriptExtension, TabIndentExtension, type TableConfig, TableExtension, type TextColorConfig, TextColorExtension, type TextColorOption, TextFormatExtension, type TextHighlightConfig, TextHighlightExtension, type TextHighlightOption, type ToolbarItem, UnderlineExtension, YouTubeEmbedExtension, appendMetadataEnvelopes, blockFormatExtension, boldExtension, clearLexicalSelection, codeExtension, codeFormatExtension, codeIntelligenceExtension, commandPaletteExtension, contextMenuExtension, createCustomNodeExtension, createEditorSystem, createEditorThemeStyleVars, createExtension, defaultLuthorTheme, draggableBlockExtension, emojiExtension, enterKeyBehaviorExtension, extractHTMLMetadataPatch, extractMarkdownMetadataPatch, extractMetadataEnvelopes, floatingToolbarExtension, fontFamilyExtension, fontSizeExtension, getDefaultPopularPrismLanguages, historyExtension, horizontalRuleExtension, htmlToJSON, iframeEmbedExtension, imageExtension, isDefaultBridgeValue, isHTMLRepresentable, isLuthorTheme, isMarkdownRepresentable, italicExtension, jsonToHTML, jsonToMarkdown, lineHeightExtension, linkExtension, listExtension, loadPopularPrismLanguages, loadPrismLanguages, markdownToJSON, mergeThemes, prepareDocumentForBridge, rehydrateDocumentFromEnvelopes, resolveLinkNodeKeyFromAnchor, richTextExtension, slashCommandExtension, strikethroughExtension, subscriptExtension, superscriptExtension, tabIndentExtension, tableExtension, textColorExtension, textHighlightExtension, underlineExtension, useBaseEditor, youTubeEmbedExtension };